<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\controller\v1;

use app\api\model\Comment as CommentModel;
use app\api\validate\FeedbackValidate;
use app\api\validate\ParameterMustBePositiveInteger;
use think\Request;

/**
 * 消息
 * Class Message
 * @package app\api\controller\v1
 */
class Comment extends BaseController
{
    /**
     * @desc 检查用户权限
     */
    protected $beforeActionList = [
        'checkUserScope' => ['only' => 'getcommentlist,getlistfromstation,insertcomment'], // 方法名必须全部小写，逗号中间不能有空格！！！
    ];

    /**
     * @Desc 获取消息列表
     *
     * @param int $page
     *
     * @return mixed
     */
    public function getCommentList($page = 1)
    {
        return CommentModel::getCommentList($page);
    }

    /**
     * @Desc 根据分类ID查询消息列表
     *
     * @param     $id
     * @param int $page
     *
     * @return mixed
     */
    public function getListFromStation($id, $page = 1)
    {
        (new ParameterMustBePositiveInteger())->scene('id')->goCheck();
        return CommentModel::getListFromStation($id, $page);
    }

    /**
     * @Desc 添加评论
     * @return \app\lib\exception\SuccessMessage
     */
    public function insertComment()
    {
        (new FeedbackValidate())->goCheck();
        $param = Request::instance()->post();
        return CommentModel::insertComment($param);
    }
}